Thanks for trying Project:M36 via this Jupyter notebook. TutorialD is a language for interacting with relational algebra databases, similar to SQL but without the historical cruft. This notebook is based on the TutorialD Tutorial.
Project:M36 is a feature-rich database management system (DBMS) which casts off the baggage of legacy DBMSes by adhering strictly to the mathematics of the relational algebra.
Please refer to the Project:M36 documentation for more detailed examples. Let's get started!
First, let's import the Chris Date example relation variables. The relation variables provided in the example are:
s supplierssp supplier-partsp parts
In [1]:
:importexample date
If you see an error in the previous cell regarding project-m36-websocket-server not being in your PATH, add the binary to your PATH and restart the jupyter server.
Let's take a look at the relation variables.
In [2]:
:showexpr s
In [3]:
:showexpr sp
In [4]:
:showexpr p
We can see that there is a many-to-many relationship between s (suppliers) and p (parts) via the sp relation variable.
Let's look at the suppliers who are in London. This is called "restriction".
Note that the relation attributes have appropriate types which restrict the values which they can contain.
In [5]:
:showexpr s where city="London"
In [6]:
:showexpr ((s where city="London") join sp join p){p#,pname,qty}
In [7]:
:showexpr (s:{statusplus10:=add(@status,10)}){s#,status,statusplus10}
Unlike most databases, Project:M36 supports relation-valued attributes. This means that database values (atoms) can also be relations. Relation-valued attributes can be represented in the notebook as nested tables of values. Note that the nested relation's type is relation {qty::Integer,pname::Text,s#::Text}.
Relation-valued attributes reduce tuple duplication by clearly associating certain values with their related multiple tuples. The group operator can also be used to create the SQL equivalent of OUTER JOIN but without the need for representing NULL in any form.
Let's list the available counts for each supplier for each part.
In [8]:
:showexpr (p join sp){qty,pname,s#,p#} group ({s#,pname,qty} as availability)
We can flatten the relation-valued attributes, thereby generating more top-level tuples.
In [9]:
:showexpr ((p join sp){qty,pname,s#,p#} group ({s#,pname,qty} as availability)) ungroup availability
In [10]:
insert s relation{tuple{s# "S6", sname "Bob", status 50, city "Boston"}}
In [11]:
:showexpr s
In [12]:
delete s where sname="Bob"
In [13]:
:showexpr s
In [14]:
update s where city="London" (status:=90)
In [15]:
:showexpr s
In [16]:
london_suppliers := s where city="London"
In [17]:
:showexpr london_suppliers
In [18]:
:constraints
Constraints are represented as "inclusion dependencies". An inclusion dependency is a generalization of all possible constraints on the database and can represent keys, uniqueness constraints, foreign key constraints, as well as span multiple relation variables.
An inclusion dependency requires that the result of relational expression sub is a subset of relational expression super.
Project:M36 includes some utilities to generate inclusion dependencies.
In [19]:
sandwich := relation{tuple{name "Cheese", price 4},tuple{name "Tuna", price 5}}
In [20]:
key sandwich_name{name} sandwich
In [21]:
insert sandwich relation{tuple{name "Tuna", price 6}}
By default, the TutorialD kernel will automatically start a project-m36-websocket-server when the first TutorialD command is executed. For this to work, project-m36-websocket-server must be in the jupyter server's PATH environment variable.
Like the python kernel, the TutorialD kernel includes some commands to interact directly with the kernel. These commands are not passed to the TutorialD interpreter.
%help brings up some help which includes links to additional documentation%connect ws://<host>:<port> <dbname> connects to the project-m36-websocket-server already running. For example:
%connect ws://localhost:64000 employees
connects to the websocket server running on the localhost on port 64000 and selects the database named "employees". Note that the database name is not part of the websocket URL.Project:M36 is a fully-featured relational algebra engine suitable for use a database. It sets out to prove that sticking to the mathematical underpinnings of the relational algebra is straightforward and results in improved correctness and performance.
If you would like to learn more, please refer to the documentation and join our welcoming community to ask questions.
In [ ]: